Creating Selection Change Event Handlers

You can create custom functions to handle selection change events in a graphics WINDOW or in a WIDGET_WINDOW. These functions must use the syntax described below.

Each function must return a value of 0 to turn off default event handling or 1 to perform default event handling.

Tip: Instead of creating a separate function for each event handler, you may find it convenient to use a custom event handling class along with the EVENT_HANDLER property. See Creating an Event Handler Class to Control Events for details on how to write this object class.

Syntax

Result = FUNCTION_NAME(Window, Graphic, Mode, WasSelected)

Where FUNCTION_NAME is the name of the callback function. This value is specified as the value of the SELECTION_CHANGE_HANDLER event keywords of WINDOW or WIDGET_WINDOW. Use a unique name representing the scope of the event handler. Avoid using the generic name "SelectionChangeHandler" to prevent name collisions with other applications using event handlers.

Return Value

The result is an array of graphics items, or a null object if nothing is currently selected.

Arguments

Window

The object reference of the window in which a graphic was selected.

Graphic

The graphic to be selected or unselected.

Mode

A value representing the mode that was used for the current selection. Possible values are:

Value

Selection Type

0

Unselect

1 Select

2

Toggled selection

3

Additive

WasSelected

A value indicating if the graphic item was already selected prior to this event. A value of 1 indicates an item was previously selected; 0 if not selected.

Example

In the following example, the selection change event handler is defined first. The procedure then draws a plot and two text annotations to illustrate how the selection change event handler works.

FUNCTION SelChange, Window, Graphic, Mode, WasSelected

PRINT, 'selection_change_handler'

HELP, Window, Graphic, Mode, WasSelected

RETURN, 1 ; Skip default event handling

END

 

PRO SELECTIONCHANGE

p=PLOT(/test)

t1=TEXT(.5, .8, 'Text 1')

t2=TEXT(.5, .5, 'Text 2')

p.window.SELECTION_CHANGE_HANDLER='SelChange'

HELP, p, t1, t2

END